<?php
namespace app\index\controller;
use think\Controller;
use think\Request;
use think\Cookie;
class News extends Common
{
    public function index()
    {
		$pageNumber=1;
		$pageSize=2;
		$isSaleOnline=true;
		if(input('?get.pageNumber')){
			$pageNumber=input('get.pageNumber');
		}
		if(input('?get.pageSize')){
			$pageSize=input('get.pageSize');
		}
		$url=config('tdwApi')."/article/list.jhtml?pageNumber=$pageNumber&pageSize=$pageSize";
		$res=$this->http($url);
		$res=json_decode($res[0],true);	
		if($res['code']==1){
			$data=$res['data']['articleArray'];
			$totalPages=$res['data']['totalPages'];
			$pageNumber=$res['data']['pageNumber'];
			$total_arr=array();
			for($i=1; $i<=$totalPages; $i++){
				$total_arr[]=$i;
			}
			//dump($data);
			return view('news/index',[
				'act'=>'news',
				'data'=>$data,
				'total_arr'=>$total_arr,
				'totalPages'=>$totalPages,
				'pageNumber'=>$pageNumber,
			]);
		}else{
			$this->error('出错了,请稍后重试',url('index/Index/index'),'',3);				
		}			
	}
	public function newsHtml()
	{
		$url = config('tdwApi')."/article/getArticleIds.jhtml";
		$res=$this->http($url);
		$res=json_decode($res[0],true);
		if($res['code']==1)
		{
			$arr=$res['data']['articleIdArray'];
			foreach ($arr as $value) {
				$id=$value['articleId'];
				$cateId=$value['articleCategoryId'];
				$result = $this->newsCreateHtml($id,$cateId);
			}
			$data['code']=200;
			$data['msg']="生成成功";			
		}else{
			$data['code']=500;
			$data['msg']="生成失败";			
		}
		echo json_encode($data);		
	}
	public function newsCreateHtml($id,$cateId)
	{
		$url=config('tdwApi')."/article/detail.jhtml?id=$id";
		$res=$this->http($url);
		$res=json_decode($res[0],true);	
		if($res['code']==1){
			$data=$res['data'];
			$this->assign('act','news');		
			$this->assign('data',$data);
			$this->buildHtml($id,'./article/'.$cateId.'/',"news/article",'utf8');		
		}
	}	
	public function article(){
		$id=input('get.id');
		$url=config('tdwApi')."/article/detail.jhtml?id=$id";
		$res=$this->http($url);
		$res=json_decode($res[0],true);	
		if($res['code']==1){
			$data=$res['data'];
			return view('news/article',[
				'act'=>'news',
				'data'=>$data,
			]);
		}else{
			$this->error('出错了,请稍后重试',url('index/Index/index'),'',3);				
		}		
	}

	public function merchants()
	{
		
		return view('news/merchants');
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
}
